/**
 * ****************************************************************************
 * Project: RoboBridge
 * ----------------------------------------------------------------------------
 * -------------------------- [c]2012 - KrawallMann ---------------------------
 * ---------------------- http://www.krawallmann.de.tc/ -----------------------
 * ****************************************************************************
 * File: SRF08OnServoFrame.java Package: tc.de.krawallmann.robobridge.visualization
 * Version: 1.0 Author(s): KrawallMann
 * ****************************************************************************
 * Description:
 * ****************************************************************************
 */
package tc.de.krawallmann.robobridge.visualization;

import java.awt.GridLayout;

import tc.de.krawallmann.robobridge.RoboBridge;
import tc.de.krawallmann.robobridge.devices.AbstractDevice;
import tc.de.krawallmann.robobridge.devices.implementation.RNControl;
import tc.de.krawallmann.robobridge.devices.implementation.SRF08;
import tc.de.krawallmann.robobridge.devices.implementation.SRF08OnServo;
import tc.de.krawallmann.robobridge.devices.implementation.Servo;
import eu.hansolo.steelseries.tools.BackgroundColor;
import eu.hansolo.steelseries.tools.FrameDesign;
import eu.hansolo.steelseries.tools.FrameEffect;

public class SRF08OnServoFrame extends AbstractRoboViewDisplay {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7198263297782630590L;

	/** The radar. */
	private final FixedRadar radar;

	private SRF08OnServo srf;

	/**
	 * Instantiates a new sR f08 frame.
	 */
	public SRF08OnServoFrame(SRF08OnServo srf) {
		super("DEVICE_ID_SRF08 @"+srf.getDeviceId());
		this.srf = srf;
		
		setLayout(new GridLayout(1, 1));
		radar = new FixedRadar();
		radar.setBackgroundColor(BackgroundColor.DARK_GRAY);
		radar.setFrameDesign(FrameDesign.SHINY_METAL);
		radar.setFrameEffect(FrameEffect.EFFECT_INNER_FRAME);
		radar.setRange(600);
		radar.animate(true);
		add(radar);
		setSize(300, 300);
		setVisible(true);
	}

	/*
	 * (non-Javadoc)
	 * @see
	 * tc.de.krawallmann.robobridge.devices.SensorListener#onSensorValueChanged
	 * (tc.de.krawallmann.robobridge.devices.AbstractDevice, java.lang.String,
	 * java.lang.Object, java.lang.Object)
	 */
	@Override
	public void onSensorValueChanged(final AbstractDevice sensor, final String propertyName,
			final Object oldValue, final Object newValue) {
		if (sensor.equals(srf)) {
			if (propertyName.equals(SRF08.SRF08_DISTANCE)) {
				radar.addPoi(new FixedPoi("P" + srf.getServo().getServoPosition(), srf.getServo()
						.getServoPosition(), (Integer) newValue, true));
			}
		}
	}

}
